﻿'
' Will Strohl (will.strohl@gmail.com)
' http://www.willstrohl.com
' http://dnntweet.codeplex.com
'
' Copyright (c) 2011, Will Strohl
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this 
' software and associated documentation files (the "Software"), to deal in the Software 
' without restriction, including without limitation the rights to use, copy, modify, 
' merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
' permit persons to whom the Software is furnished to do so, subject to the following 
' conditions:
'
' The above copyright notice and this permission notice shall be included in all copies 
' or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
' INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
' PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
' HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
' OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'

Imports DotNetNuke.Entities.Modules
Imports DotNetNuke.Services.Localization
Imports WillStrohl.Modules.Twitter.TwitterController

Namespace WillStrohl.Modules.Twitter

    Public MustInherit Class WNSPortalModuleBase
        Inherits PortalModuleBase

#Region " Private Member "

        Private p_TwitterConsumerKey As String = Null.NullString
        Private p_TwitterConsumerSecret As String = Null.NullString
        Private p_TwitterSearchTerms As String = Null.NullString
        Private p_TwitterRefreshRate As Integer = Null.NullInteger
        Private p_jQueryUIHosted As Nullable(Of Boolean) = Nothing
        Private p_jQueryUITheme As String = Null.NullString
        Private p_SettingsGlobal As Nullable(Of Boolean) = Nothing

#End Region

#Region " Protected Properties "

        Protected ReadOnly Property TwitterConsumerKey() As String
            Get
                If Not String.IsNullOrEmpty(Me.p_TwitterConsumerKey) Then
                    Return Me.p_TwitterConsumerKey
                End If

                Dim obj As Object = Settings(TWITTER_CONSUMER_KEY)
                If Not obj Is Nothing Then
                    Me.p_TwitterConsumerKey = obj.ToString
                End If

                Return Me.p_TwitterConsumerKey
            End Get
        End Property

        Protected ReadOnly Property TwitterConsumerSecret() As String
            Get
                If Not String.IsNullOrEmpty(Me.p_TwitterConsumerSecret) Then
                    Return Me.p_TwitterConsumerSecret
                End If

                Dim obj As Object = Settings(TWITTER_CONSUMER_SECRET_KEY)
                If Not obj Is Nothing Then
                    Me.p_TwitterConsumerSecret = obj.ToString
                End If

                Return Me.p_TwitterConsumerSecret
            End Get
        End Property

        Protected ReadOnly Property TwitterSearchTerms() As String
            Get
                If Not String.IsNullOrEmpty(Me.p_TwitterSearchTerms) Then
                    Return Me.p_TwitterSearchTerms
                End If

                Dim obj As Object = Settings(TWITTER_SEARCH_TERMS_KEY)
                If Not obj Is Nothing Then
                    Me.p_TwitterSearchTerms = obj.ToString
                End If

                Return Me.p_TwitterSearchTerms
            End Get
        End Property

        Protected ReadOnly Property TwitterRefreshRate() As Integer
            Get
                If Me.p_TwitterRefreshRate > Null.NullInteger Then
                    Return Me.p_TwitterRefreshRate
                End If

                Dim obj As Object = Settings(TWITTER_REFRESH_RATE_KEY)
                If Not obj Is Nothing Then
                    Me.p_TwitterRefreshRate = Integer.Parse(obj.ToString, Globalization.NumberStyles.Integer)
                Else
                    Me.p_TwitterRefreshRate = 60
                End If

                Return Me.p_TwitterRefreshRate
            End Get
        End Property

        Protected ReadOnly Property jQueryUIHosted() As Boolean
            Get
                If Me.p_jQueryUIHosted.HasValue Then
                    Return Me.p_jQueryUIHosted.Value
                End If

                Dim obj As Object = Settings(JQUERYUI_HOSTED_KEY)
                If Not obj Is Nothing Then
                    Me.p_jQueryUIHosted = Boolean.Parse(obj.ToString)
                Else
                    Me.p_jQueryUIHosted = True
                End If

                Return Me.p_jQueryUIHosted.Value
            End Get
        End Property

        Protected ReadOnly Property jQueryUITheme() As String
            Get
                If Not String.IsNullOrEmpty(Me.p_jQueryUITheme) Then
                    Return Me.p_jQueryUITheme
                End If

                Dim obj As Object = Settings(JQUERYUI_THEME_KEY)
                If Not obj Is Nothing Then
                    Me.p_jQueryUITheme = obj.ToString
                Else
                    Me.p_jQueryUITheme = "ui-lightness"
                End If

                Return Me.p_jQueryUITheme
            End Get
        End Property

        Protected ReadOnly Property SettingsGlobal() As Boolean
            Get
                If Me.p_SettingsGlobal.HasValue Then
                    Return Me.p_SettingsGlobal.Value
                End If

                Dim obj As Object = Settings(SETTINGS_GLOBAL)
                If Not obj Is Nothing Then
                    Me.p_SettingsGlobal = Boolean.Parse(obj.ToString)
                Else
                    Me.p_SettingsGlobal = True
                End If

                Return Me.p_SettingsGlobal.Value
            End Get
        End Property

#End Region

#Region " Localization "

        Protected Overloads Function GetLocalizedString(ByVal LocalizationKey As String) As String
            If Not String.IsNullOrEmpty(LocalizationKey) Then
                Return Localization.GetString(LocalizationKey, Me.LocalResourceFile)
            Else
                Return String.Empty
            End If
        End Function

        Protected Overloads Function GetLocalizedString(ByVal LocalizationKey As String, ByVal LocalResourceFilePath As String) As String
            If Not String.IsNullOrEmpty(LocalizationKey) Then
                Return Localization.GetString(LocalizationKey, LocalResourceFilePath)
            Else
                Return String.Empty
            End If
        End Function

#End Region

#Region " Event Handlers "

        Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            ' request that the DNN framework load the jQuery script into the markup
            DotNetNuke.Framework.jQuery.RegisterDnnJQueryPlugins(Me.Page)

        End Sub

#End Region

    End Class

End Namespace